package org.xu.upms.server;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

public class test {
	public static void main(String[] args) {
	//HashMap<Long, String> map=new HashMap<Long, String>();
		
		ConcurrentHashMap<Long, String> map = new ConcurrentHashMap<Long, String>();  
		for (long i = 0; i < 15; i++) {  
			map.put(i, i + "");  
        }  
		//hashMap遍历删除报错java.util.ConcurrentModificationException
		//ConcurrentHashMap遍历删除不会报错
		for (Entry<Long, String> entry : map.entrySet()) {
			Long key = entry.getKey();
			String value = entry.getValue(); 
			if (key < 10) {  
				map.remove(key);  
            }  
		}
		//迭代器删除元素 不会报错
	/*	 for (Iterator<Entry<Long, String>> iterator = map.entrySet().iterator(); iterator.hasNext();) {  
	            Entry<Long, String> entry = iterator.next();  
	            long key = entry.getKey();  
	            if (key < 10) {  
	                iterator.remove();  
	            }  
	        } */ 
	  
	        for (Entry<Long, String> entry : map.entrySet()) {  
	        	System.out.println(entry.getKey() + " " + entry.getValue());
	        }  
	}
}
